<?php
include('../../includes/classes/core.php');
 
$user_id		= $_SESSION['USERID'];
$warehouse_id	= $_REQUEST['id'];
$page = '(1/1)';

$rResult = mysql_fetch_array(mysql_query("SELECT	`d_letter`.`id` as `id`,
													CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client` ,
													`d_letter`.`planned_end_date`
										FROM		`d_letter`
										LEFT JOIN	`client_objects`	ON `client_objects`.`id` = `d_letter`.`client_object_id`
										LEFT JOIN	`client` ON `client`.`id` = `client_objects`.`client_id`
										RIGHT JOIN	`warehouse` ON `warehouse`.`d_letter_id` = `d_letter`.`id`
										WHERE		`warehouse`.`id` = $warehouse_id"));

$rResult1 = mysql_fetch_array(mysql_query("SELECT		`persons`.`name` as `name`
											FROM		persons
											LEFT JOIN	users ON users.person_id = persons.id
											WHERE  		users.id = $user_id"));


function print1($rResult){
	GLOBAL $warehouse_id;
	GLOBAL $page;
	$data = '';
	$rsQl = mysql_query("SELECT			`printer_parts_type`.`name`,
										`production`.`name`,
										`warehouse_detail`.`barcode`,
										`persons`.`name` as `person`
						FROM    		`warehouse_producing`
						JOIN		`warehouse_detail` ON warehouse_detail.id	= warehouse_producing.warehouse_detail_id
						LEFT JOIN		`warehouse` ON `warehouse`.`id` = `warehouse_detail`.`warehouse_id`
						LEFT JOIN		`production` ON `production`.`id` = `warehouse_detail`.`prod_id`
						LEFT JOIN		printer_parts_type ON printer_parts_type.id = warehouse_producing.printer_part_id
						LEFT JOIN		client_objects ON client_objects.id = warehouse.client_object_id
						LEFT JOIN		client ON client.id = client_objects.client_id
						LEFT JOIN		persons ON persons.id = warehouse_producing.person_id
						WHERE			warehouse.id = '$warehouse_id'");
	
	if( mysql_num_rows($rsQl) <= 40 ){
		for($j=1;$j<=40;$j++){
			while( $rezsQl = mysql_fetch_array($rsQl) ){
				$data .= '<tr>';
				for ( $i = 0 ; $i < 4 ; $i++ ){
					$data .='<td>'.$rezsQl[$i].'</td>';
				}
				$data .= '</tr>';
				$j++;
			}
			$data .='
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
			';
		}
		
		
		$data .='
		</table>
		<div style="margin-top: 80px; margin-left: 40px; float: left;">
		სს " '. $rResult['client'] .' " შეკვეთა № :&nbsp;'.'დ – '. $rResult['id'] .' &nbsp;'. $rResult['planned_end_date'] .'
		</div>
		<div style="margin-top: 80px; float: right;">
			'. $page .'
		</div>';	
		
		
	}else if( mysql_num_rows($rsQl) <= 88 ){
		$page = '(1/2)';
		$j=1;
		for($j=1;$j<=40;$j++){
			$rezsQl = mysql_fetch_array($rsQl);
			$data .= '<tr>';
			for ( $i = 0 ; $i < 4 ; $i++ ){
				$data .='<td>'.$rezsQl[$i].'</td>';
			}
			$data .= '</tr>';		
		}		
		$data .='
		</table>
		<div style="margin-top: 80px; margin-left: 40px; float: left;">
		სს " '. $rResult['client'] .' " შეკვეთა № :&nbsp;'. $rResult['id'] .' &nbsp;'. $rResult['planned_end_date'] .'
		</div>
		<div style="margin-top: 80px; float: right; padding-bottom: 100px;">
			'. $page .'
		</div>';		
		$page = '(2/2)';
		$data .='<table border="1" class="job-blank" cellpadding="0" cellspacing="0">';
		for( ;$j<= 88;$j++){
			while( $rezsQl = mysql_fetch_array($rsQl) ){
				while( $rezsQl = mysql_fetch_array($rsQl) ){
					$data .= '<tr>';
					for ( $i = 0 ; $i < 4 ; $i++ ){
						$data .='<td>'.$rezsQl[$i].'</td>';
					}
					$data .= '</tr>';
					$j++;
				}
			}
				
		}
		$data .='
		</table>
		<div style="margin-top: 80px; margin-left: 40px; float: left; vertical-align:bottom;">
		სს " '. $rResult['client'] .' " შეკვეთა № : '.'ა – '. $rResult['id'] .' &nbsp;'. $rResult['planned_end_date'] .'
		</div>
		<div style="margin-top: 80px; float: right;">
			'. $page .'
		</div>';
	}

	return $data;
}

?>


<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>სამუშაო ბლანკი</title>
	<style type="text/css">
		body{
			margin:20px;
		}
		
		.job-blank{
			width: 800px;
		}
		
		.job-blank td{
			text-align: center;
			font-weight: bold;
			font-family: Sylfaen, Arial, sans-serif;
			font-size: 10.0pt;
		}
	</style>
</head>

<body>
	<table border="0" class="job-blank" cellpadding="0" cellspacing="0">
		<tr>
			<td rowspan="4" valign="top" style="padding: 2px;"><img src="logo.jpg" width="68" height="68" style="float: left;"></td>
			<td style="font-size: 12pt; padding-top: 15px;">წარმოების ბლანკი</td>
			<td colspan="2" style="font-weight: normal; padding-top: 5px; text-align: right;">შეკვეთა № :<span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 10px;"><?php echo 'დ – '.$rResult['id']; ?></span></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td rowspan="2" style="font-size: 14pt; padding-top: 10px;"><?php echo  $rResult['planned_end_date']; ?></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td style="font-weight: normal; text-align: right;">შესრულების გეგმიური დრო</td>
		</tr>
		<tr>
			<td colspan="2" >&nbsp;</td>
			<td colspan="2">&nbsp;</td>
		</tr>
		<tr>
			<td colspan="2" style="font-weight: normal; text-align: right;">მომსახურების ობიექტი:</td>
			<td colspan="2" style="font-size: 10pt; text-align: left;"><span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 50px;"><?php echo  $rResult['client']; ?></span></td>
		</tr>
		<tr>
			<td colspan="2" style="font-weight: normal; text-align: right;">ტესტერი:</td>
			<td colspan="2"><?php echo $rResult1['name']; ?></td>
		</tr>		
		<tr>
			<td colspan="2">&nbsp;</td>
			<td colspan="2">&nbsp;</td>
		</tr>
	</table>
	
	<table border="1" class="job-blank" cellpadding="0" cellspacing="0">
		<tr style="background-color: black;">
			<td style="width: 37%;font-size: 9pt; color: white;"><span>სერვისი</span></td>
			<td style="width: 20%;font-size: 9pt; color: white;"><span>მოდელი</span></td>
			<td style="width: 18%;font-size: 9pt; color: white;"><span>შტრიხკოდი</span></td>
			<td style="width: 25%;font-size: 9pt; color: white;"><span>შემსრულებელი</span></td>			
		</tr>
		<?php echo print1($rResult);?>
	
</body>

</html>